package com.mp.chart.charts;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mp.chart.components.AJXAxis;
import com.mp.chart.components.AJYAxis;
import com.mp.chart.components.Legend;
import com.mp.chart.components.LimitLine;
import com.mp.chart.components.MarkerView;
import com.mp.chart.components.XAxis;
import com.mp.chart.components.YAxis;
import com.mp.chart.data.BarData;
import com.mp.chart.data.BarDataSet;
import com.mp.chart.data.BarEntry;
import com.mp.chart.data.Entry;
import com.mp.chart.data.LineData;
import com.mp.chart.data.LineDataSet;
import com.mp.chart.data.MinutesData;
import com.mp.chart.formatter.ValueFormatter;
import com.mp.chart.formatter.XValueFormatter;
import com.mp.chart.listener.OnChartGestureListener;
import com.mp.chart.listener.OnChartValueSelectedListener;
import com.mp.chart.listener.OnMarketSelectValueListener;
import com.mp.chart.markerview.HightCircleMarkerView;
import com.mp.chart.utils.DateUtil;
import com.mp.chart.utils.Highlight;
import com.mp.chart.utils.Utils;
import com.mp.chart.view.ShinePointView;
import com.android.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 分时图（包括上+下）
 */
public class MinutesChart extends LinearLayout implements OnChartValueSelectedListener {

    private MinutesLineChart mLineChart;
    private MinutesBarChart mBarChart;
    private AJYAxis mlineChartAxisLeft;
    private AJYAxis mlineChartAxisRight;
    private AJYAxis mbarChartAxisLeft;
    private int mHighLightColor;
    private AJXAxis mBarChartXAxis;
    private OnMarketSelectValueListener mOnMarketSelectValueListener;
    private AJXAxis mlineChartXAxis;
    private float leftOffset;
    private float rightOffset;
    private boolean mDrawLinePathFillEnabled;
    private int mXLabelPosition;
    private int minuteAverageLineColor = 0xFFF9AE57;
    private int minuteLinePathFillColor = 0x6571A3C8;
    private ArrayList<Entry> lineMin1Entries;
    private ArrayList<Entry> lineMin2Entries;
    private ArrayList<Entry> lineMin3Entries;
    private ArrayList<Entry> lineMin4Entries;
    private LineDataSet lineMin1, lineMin2, lineMin3, lineMin4;
    private TextView maxVolumeTextView;

    public MinutesChart(Context context) {
        super(context);
        init(context);
    }

    public MinutesChart(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public MinutesChart(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        setOrientation(VERTICAL);
        /*上*/
        mLineChart = new MinutesLineChart(context);
        mBarChart = new MinutesBarChart(context);
        addView(mLineChart, new LayoutParams(LayoutParams.MATCH_PARENT, 0, 3));


        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        RelativeLayout relativeLayout = new RelativeLayout(getContext());
        relativeLayout.setLayoutParams(layoutParams);

        ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        ViewGroup.LayoutParams vlp2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        maxVolumeTextView = new TextView(getContext());

        maxVolumeTextView.setTextSize(10);

        maxVolumeTextView.setTextColor(getResources().getColor(R.color.main_text));

        mBarChart.setLayoutParams(vlp);

        maxVolumeTextView.setLayoutParams(vlp2);

        relativeLayout.addView(mBarChart);

        relativeLayout.addView(maxVolumeTextView);

        addView(relativeLayout, new LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));

        /*初始化高亮颜色*/
        initChartSetting();

    }

    public void setMaxVolume(String maxVolume) {
        maxVolumeTextView.setText(maxVolume);
    }

    private void initChartSetting() {
        mLineChart.setNoDataText("");
        mBarChart.setNoDataText("");
        mLineChart.setHighlightEnabled(true);
        mLineChart.setTouchEnabled(true);

        mLineChart.setDragEnabled(true);
        mLineChart.setScaleEnabled(false);
        mLineChart.setDrawGridBackground(false);
        mLineChart.setHighlightPerDragEnabled(true);

        /*图例*/
        Legend l = mLineChart.getLegend();
        l.setEnabled(false);
        /*y坐标轴*/
        mlineChartAxisRight = mLineChart.getAxisRight();
        mlineChartAxisLeft = mLineChart.getAxisLeft();
        mlineChartXAxis = mLineChart.getXAxis();
        // mlineChartXAxis.drawGridDashedLine(mLineChart.DEFAULT_DASH_EFFECT);

        mlineChartAxisLeft.setStartAtZero(false);
        mlineChartAxisLeft.setDrawAxisLine(false);//去掉左y
        mlineChartAxisLeft.setDrawGridLines(true);
        // mlineChartAxisLeft.drawGridDashedLine(mLineChart.DEFAULT_DASH_EFFECT);
        mlineChartAxisRight.setStartAtZero(false);
        mlineChartAxisRight.setDrawGridLines(false);
        mlineChartAxisRight.setDrawAxisLine(false);
//        setYLabelStatic(true);
        mlineChartXAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

        mLineChart.setOnChartValueSelectedListener(this);
        mLineChart.requestDisallowInterceptTouchEvent(true);
        mBarChart.requestDisallowInterceptTouchEvent(true);

//        barChart设置
        mBarChart.setScaleEnabled(false);
        mBarChart.setDrawGridBackground(false);
        mBarChartXAxis = mBarChart.getXAxis();
        mBarChartXAxis.setDrawGridLines(true);
//        mBarChartXAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

        mBarChart.getLegend().setEnabled(false);
        mBarChart.getAxisRight().setEnabled(false);
//        mBarChart.getAxisRight().setDrawLabels(false);
//        mBarChart.getAxisRight().setDrawGridLines(false);
        mBarChart.getAxisLeft().setDrawGridLines(false);

        mBarChart.setDoubleTapToZoomEnabled(false);
        mBarChart.setPinchZoom(false);

        mBarChart.setTouchEnabled(true);
        mbarChartAxisLeft = mBarChart.getAxisLeft();
        mbarChartAxisLeft.setTextColor(getResources().getColor(R.color.mainFontColor));
        mbarChartAxisLeft.setDrawAxisLine(false);//去掉左y
//        mBarChart.setLongPressEnable(false);
        mBarChart.setOnChartValueSelectedListener(this);
        setYAxixPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
        /*设置x轴标签显示位置，可在折线图下面或者柱状图下面*/
        setXLabelPosition(AJXAxis.XAXISPOSITION_MIDDLE);
    }

    //设置y轴label是否固定
    public void setYLabelStatic(boolean b) {
        mlineChartAxisLeft.setYlabelStatic(b);
        mlineChartAxisRight.setYlabelStatic(b);
    }


    /**
     * @param position:AJXAxis.XAXISPOSITION_BOTTOM,XAXISPOSITION_MIDDLE
     */
    public void setXLabelPosition(int position) {
        float offset = Utils.convertDpToPixel(5);
        this.mXLabelPosition = position;
        if (position == AJXAxis.XAXISPOSITION_MIDDLE) {
            mlineChartXAxis.setDrawLabels(true);
            mBarChartXAxis.setDrawLabels(false);
        } else if (position == AJXAxis.XAXISPOSITION_BOTTOM) {
            mlineChartXAxis.setDrawLabels(false);
            mBarChartXAxis.setDrawLabels(true);
        }

        mLineChart.setExtraOffsets(offset, offset, offset, offset);
    }

    public void setDrawBorder(int color, float width) {
        mLineChart.setDrawBorders(true);
        mBarChart.setDrawBorders(true);

        mLineChart.setBorderColor(color);
        mBarChart.setBorderColor(color);

        mLineChart.setBorderWidth(width);
        mBarChart.setBorderWidth(width);
    }

    public void setYAxixPosition(YAxis.YAxisLabelPosition pos) {
        mlineChartAxisLeft.setPosition(pos);
        mlineChartAxisRight.setPosition(pos);
        mbarChartAxisLeft.setPosition(pos);
    }

    public void setAxisLeftValueFormatter(ValueFormatter format) {
        mlineChartAxisLeft.setValueFormatter(format);
    }

    public void setAxisRightValueFormatter(ValueFormatter format) {
        mlineChartAxisRight.setValueFormatter(format);
    }

    public void setBarValueFormatter(ValueFormatter format) {

        mbarChartAxisLeft.setValueFormatter(format);
    }


    public void showDrawYLabels(boolean enable) {
        showLineDrawYLabels(enable);
    }


    public void showLineDrawYLabels(boolean enable) {
        mlineChartAxisRight.setDrawLabels(enable);
        mlineChartAxisLeft.setDrawLabels(enable);
    }


    /*只显示基准线和最大最小，如果想自定义显示label个数，则此处不能调用*/
    public void showLineMaxMinLabels(boolean show) {
        mlineChartAxisLeft.setShowBaseValueAndMaxmin(show);
        mlineChartAxisRight.setShowBaseValueAndMaxmin(show);
    }


    public void setShowLabels(SparseArray<String> labels) {
//        Log.e("****", labels.size() + "");
        mlineChartXAxis.setShowLabels(labels);
        mBarChartXAxis.setShowLabels(labels);
    }

    public void setBaseLine(float value, int color) {
        mlineChartAxisLeft.setBaseValue(value);
        mlineChartAxisRight.setBaseValue(0);
        mlineChartAxisLeft.getLimitLines().clear();
        LimitLine ll = new LimitLine(value);
        ll.setLineWidth(1f);
        ll.setLineColor(color);
        ll.drawGridDashedLine(mLineChart.DEFAULT_DASH_EFFECT);
        ll.setLineWidth(1);
        mlineChartAxisLeft.addLimitLine(ll);
    }

    public void setBaseLine(float value) {
        setBaseLine(value, getResources().getColor(R.color.main_white));
    }

    public void setMarkerView(MarkerView leftView, MarkerView xaxisView) {
        mLineChart.setLeftMarkerView(leftView);
        mLineChart.setXAxisMarkerView(xaxisView);
    }

    public void setLRMarkerView(MarkerView quoteInfoView, MarkerView leftView, MarkerView rightView, MarkerView xaxisView) {
        mLineChart.setQuoteInfoMarkerView(quoteInfoView);
        mLineChart.setLeftMarkerView(leftView);
        mLineChart.setRightMarkerView(rightView);
        mLineChart.setXAxisMarkerView(xaxisView);
    }

    public void setHighLightCircle(HightCircleMarkerView highLightCircle) {
        mLineChart.setHighLightCircleView(highLightCircle);
    }

    public void setQuoteInfoMarkerView(MarkerView quoteInfoMarkerView) {
        mLineChart.setQuoteInfoMarkerView(quoteInfoMarkerView);
    }

    public void setTopMarkerView(MarkerView topView) {
        mLineChart.setTopMarkerView(topView);
    }

    public void setLeftMarkerView(MarkerView leftView) {
        mLineChart.setLeftMarkerView(leftView);
    }

    public void setRightMarkerView(MarkerView rightView) {
        mLineChart.setRightMarkerView(rightView);
    }

    public void setLeftRightOffset(float left, float right) {
        this.leftOffset = left;
        this.rightOffset = right;
    }

    @Override
    public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
//        QuoteStockInfoActivity.canRefresh = false;
//        Log.e("touch", "onValueSelected");
        //触碰line高亮，联动bar
        Entry entry = mLineChart.highlightTouchWithoutEvent(new Highlight(e.getXIndex(), 0), 1);
        //触碰bar高亮，联动line
        Entry barEntry = mBarChart.highlightTouchWithoutEvent(new Highlight(e.getXIndex(), 0), 0);
        if (mOnMarketSelectValueListener != null) {
            mOnMarketSelectValueListener.onValueSelected(e.getXIndex(), entry, barEntry);
        }
    }

    @Override
    public void onNothingSelected() {
//        QuoteStockInfoActivity.canRefresh = true;
//        Log.e("touch", "onNothingSelected");
        mLineChart.highlightTouchWithoutEvent(null, 0);
        mBarChart.highlightTouchWithoutEvent(null, 0);

        if (mOnMarketSelectValueListener != null) {
            mOnMarketSelectValueListener.onValueNothing();
        }
    }

    public void setOnMarketSelectValueListener(OnMarketSelectValueListener l) {
        this.mOnMarketSelectValueListener = l;
    }

    /*自定义设定最值后,space属性失效,故重写最值.此方法舍弃！*/
    public void setMaxMin(float lmax, float lmin, float rmax, float rmin, float space) {
        float leftRange = Math.abs(lmax - (mlineChartAxisLeft.isStartAtZeroEnabled() ? 0 : lmin));
        float rightRange = Math.abs(rmax - (mlineChartAxisRight.isStartAtZeroEnabled() ? 0 : rmin));
        // in case all values are equal
        if (leftRange == 0f) {
            lmax = lmax + 1f;
            if (!mlineChartAxisLeft.isStartAtZeroEnabled())
                lmin = lmin - 1f;
        }
        if (rightRange == 0f) {
            rmax = rmax + 1f;
            if (!mlineChartAxisRight.isStartAtZeroEnabled())
                rmin = rmin - 1f;
        }

        float spaceLeft = leftRange / 100f * space;
        float spaceRight = rightRange / 100f * space;


        mlineChartAxisLeft.mAxisMaximum = !Float.isNaN(mlineChartAxisLeft.getAxisMaxValue()) ? mlineChartAxisLeft
                .getAxisMaxValue() : lmax + spaceLeft;
        mlineChartAxisRight.mAxisMaximum = !Float.isNaN(mlineChartAxisRight.getAxisMaxValue()) ? mlineChartAxisRight
                .getAxisMaxValue() : rmax + spaceRight;
        mlineChartAxisLeft.mAxisMinimum = !Float.isNaN(mlineChartAxisLeft.getAxisMinValue()) ? mlineChartAxisLeft
                .getAxisMinValue() : lmin - spaceLeft;
        mlineChartAxisRight.mAxisMinimum = !Float.isNaN(mlineChartAxisRight.getAxisMinValue()) ? mlineChartAxisRight
                .getAxisMinValue() : rmin - spaceRight;

        mlineChartAxisLeft.setAxisMaxValue(mlineChartAxisLeft.mAxisMaximum);
        mlineChartAxisLeft.setAxisMinValue(mlineChartAxisLeft.mAxisMinimum);
        mlineChartAxisRight.setAxisMaxValue(mlineChartAxisRight.mAxisMaximum);
        mlineChartAxisRight.setAxisMinValue(mlineChartAxisRight.mAxisMinimum);


    }

    /**
     * 以baseline为准,上下各显示多少Y轴坐标
     *
     * @param lableCount
     */
    public void setLabelCount(int lableCount) {
        mlineChartAxisLeft.setLabelCount(lableCount);
        mlineChartAxisRight.setLabelCount(lableCount);
    }


    /*设置对齐*/
    private void setOffset() {

        float offsetLeft = 0;
        float offsetRight = 0;


        float lMax1 = this.leftOffset;
        if (mlineChartAxisLeft.needsOffset()) {
            lMax1 = mlineChartAxisLeft.getRequiredWidthSpace(mLineChart.getRendererLeftYAxis().getPaintAxisLabels());
            Log.e("!!!", "1" + lMax1);
        }

        float lMax2 = 0;


        float rMax = this.rightOffset;
        if (mlineChartAxisRight.needsOffset()) {
            rMax = mlineChartAxisRight.getRequiredWidthSpace(mLineChart.getRendererRightYAxis().getPaintAxisLabels());
            Log.e("!!!", "3" + rMax);
        }

        if (lMax1 < lMax2) {
            lMax1 = lMax2;
            Log.e("!!!", "4");
        }


        offsetLeft = Utils.convertPixelsToDp(lMax1);
        offsetRight = Utils.convertPixelsToDp(rMax);


        mLineChart.setExtraLeftOffset(offsetLeft);
        mLineChart.setExtraRightOffset(offsetRight);

        mLineChart.setExtraTopOffset(10);//距离tab
    }

    int type = 0;

    /**
     * 设置xY数据并且设置一些样式属性
     *
     * @param xValue      x轴数据
     * @param yValue      y轴数据
     * @param minutesType 分时图的类型：
     *                    0：分时，
     *                    1：五日,添加四条辅助线
     */
    public void setData(String[] xValue, ArrayList<MinutesData> yValue, int minutesType, final boolean isZS) {
        this.type = minutesType;
        String[] xValueTemp = xValue;
        ArrayList<Entry> chengjiaojiaList = new ArrayList<>();
        ArrayList<BarEntry> chengjiaoliangList = new ArrayList<>();
        ArrayList<Entry> junjiaList = new ArrayList<>();
        if (type == 1) {
            lineMin1Entries = new ArrayList<>();
            lineMin2Entries = new ArrayList<>();
            lineMin3Entries = new ArrayList<>();
            lineMin4Entries = new ArrayList<>();
        }
        int valueCount = yValue.size();
        SparseArray<String> showLabels = mlineChartXAxis.getShowLabels();

        for (int i = 0, x = 0; x < valueCount; i++, x++) {
            //纵轴数据（成交价，均价，成交量）
            MinutesData t = yValue.get(x);

            if (t == null) {

                chengjiaojiaList.add(new Entry(Float.NaN, i, t));
                junjiaList.add(new Entry(Float.NaN, i));
                chengjiaoliangList.add(new BarEntry(Float.NaN, i, t));
                if (type == 1 && lineMin1Entries != null && lineMin2Entries != null && lineMin3Entries != null && lineMin4Entries != null) {
                    lineMin1Entries.add(new BarEntry(Float.NaN, i));
                    lineMin2Entries.add(new BarEntry(Float.NaN, i));
                    lineMin3Entries.add(new BarEntry(Float.NaN, i));
                    lineMin4Entries.add(new BarEntry(Float.NaN, i));
                }
                continue;
            }

            chengjiaojiaList.add(new Entry(t.chengjiaojia, i, t));
            junjiaList.add(new Entry(t.junjia, i));
            chengjiaoliangList.add(new BarEntry(t.chengjiaoliang, i, t));

            if (type == 1 && lineMin1Entries != null && lineMin2Entries != null && lineMin3Entries != null && lineMin4Entries != null) {
                lineMin1Entries.add(new Entry(i, 97));
                lineMin2Entries.add(new Entry(i, 195));
                lineMin3Entries.add(new Entry(i, 293));
                lineMin4Entries.add(new Entry(i, 392));
            }

        }
        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(chengjiaojiaList, "成交价");
        setLineDateSetStyle(set1);
        set1.setColor(this.getResources().getColor(R.color.minuteLineColor));
        set1.setFillAlpha(65);
        set1.setLineWidth(0.6f);
        set1.setDrawFilled(true);
        set1.setFillColor(Color.argb(225, 110, 109, 115));//灰色
        set1.setCircleColor(Color.argb(225, 110, 109, 115));//灰色

        LineDataSet set2 = null;
        set2 = new LineDataSet(junjiaList, "均价");
        setLineDateSetStyle(set2);
        set2.setHighlightEnabled(false);
        set2.setColor(this.minuteAverageLineColor);
        //如果是三大指数，则隐藏均价线。指数没有均价。
        if (!isZS) {
            set2.setVisible(true);
        } else {
            set2.setVisible(false);
        }
        BarDataSet barDataSet = new BarDataSet(chengjiaoliangList, "成交量");
        barDataSet.setBarSpacePercent(2); //bar空隙
        barDataSet.setHighLightColor(mHighLightColor);
        barDataSet.setHighLightAlpha(255);
        barDataSet.setDrawValues(false);
//        barDataSet.setBarShadowColor(this.getResources().getColor(R.color.white));

        if (type == 1) {
            lineMin1 = new LineDataSet(lineMin1Entries, "辅助线1");
            lineMin2 = new LineDataSet(lineMin2Entries, "辅助线2");
            lineMin3 = new LineDataSet(lineMin3Entries, "辅助线3");
            lineMin4 = new LineDataSet(lineMin4Entries, "辅助线4");

            lineMin1.setDrawValues(false);
            lineMin1.setDrawCircleHole(false);
            lineMin1.setDrawCircles(false);
            lineMin1.setDrawCubic(false);
            lineMin1.setLineWidth(1.5f);
            lineMin1.setColor(Color.argb(255, 24, 23, 29));
            lineMin1.setHighlightEnabled(false);

            lineMin2.setDrawValues(false);
            lineMin2.setDrawCircleHole(false);
            lineMin2.setDrawCircles(false);
            lineMin2.setDrawCubic(false);
            lineMin2.setLineWidth(1.5f);
            lineMin2.setColor(Color.argb(255, 24, 23, 29));
            lineMin2.setHighlightEnabled(false);

            lineMin3.setDrawValues(false);
            lineMin3.setDrawCircleHole(false);
            lineMin3.setDrawCircles(false);
            lineMin3.setDrawCubic(false);
            lineMin3.setLineWidth(1.5f);
            lineMin3.setColor(Color.argb(255, 24, 23, 29));
            lineMin3.setHighlightEnabled(false);

            lineMin4.setDrawValues(false);
            lineMin4.setDrawCircleHole(false);
            lineMin4.setDrawCircles(false);
            lineMin4.setDrawCubic(false);
            lineMin4.setLineWidth(1.5f);
            lineMin4.setColor(Color.argb(255, 24, 23, 29));
            lineMin4.setHighlightEnabled(false);
        }

        //bar的颜色,收盘价>开盘价为红
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < yValue.size(); i++) {
            if (i > 0) {
                if (yValue.get(i).chengjiaoliang > yValue.get(i - 1).chengjiaoliang) {
                    list.add(Color.argb(225, 110, 109, 115));
                } else {
                    list.add(Color.argb(225, 110, 109, 115));
                }
            }
        }
        barDataSet.setColor(Color.argb(225, 110, 109, 115));
        ArrayList<BarDataSet> barDataSets = new ArrayList<>();
        barDataSets.add(barDataSet);

        ArrayList<LineDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);
        dataSets.add(set2);

        if (type == 1 && lineMin1 != null && lineMin2 != null && lineMin3 != null && lineMin4 != null) {
            dataSets.add(lineMin1);
            dataSets.add(lineMin2);
            dataSets.add(lineMin3);
            dataSets.add(lineMin4);
        }

        //折线图添加两组数据
        mLineChart.setData(new LineData(xValueTemp, dataSets));
        mBarChart.setData(new BarData(xValueTemp, barDataSets));


        setOffset();

    }

    public void setFiveData(List<Entry> chengjiaojiaList, List<Integer> xlabelIndexs, List<Long> xlabelValue, int currentCount) {
        LineDataSet set1 = new LineDataSet(chengjiaojiaList, "成交价");
        setLineDateSetStyle(set1);
        set1.setColor(this.getResources().getColor(R.color.minuteLineColor));
        set1.setDrawFilled(false);
        set1.setFillAlpha(65);
        set1.setLineWidth(0.6f);
        set1.setFillColor(this.getResources().getColor(R.color.minuteLineColor));
        ArrayList<LineDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);
        //折线图添加两组数据进去
        //setShowLabels(initAxisX(xlabelIndexs, xlabelValue));
        mLineChart.setData(new LineData(new String[currentCount], dataSets));
        setOffset();
    }

    /*x轴坐标*/
    protected SparseArray<String> initAxisX(List<Integer> xlabelIndexs, List<Long> xlabelValues) {
        SparseArray<String> titleX = new SparseArray<String>();
        for (int i = 0; i < 5; i++) {
            titleX.put(xlabelIndexs.get(i), DateUtil.converTime(xlabelValues.get(i), "MM-dd", 0));
        }


        return titleX;
    }

    /*只显示bar的最大值*/
    public void setBarMaxText(String txt) {
        mBarChart.getAxisLeft().setShowOnlyMax(txt);
        mBarChart.getAxisLeft().setTextColors(Color.TRANSPARENT);
    }

    public void setBarMaxValue(float volume) {
        mBarChart.getAxisLeft().setAxisMaxValue(volume);
    }

    public void setLineMaxMinValue(float leftMaxValue, float leftMinValue, float rightMaxValue, float rightMinValue) {
        mlineChartAxisLeft.setAxisMaxValue(leftMaxValue);
        mlineChartAxisLeft.setAxisMinValue(leftMinValue);
        mlineChartAxisRight.setAxisMaxValue(rightMaxValue);
        mlineChartAxisRight.setAxisMinValue(rightMinValue);
    }

    private void setLineDateSetStyle(LineDataSet dataSet) {
        dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);//对应指定轴（左边价格）
        dataSet.setDrawCircles(false);
        dataSet.setDrawValues(false);
        //  dataSet.setLineWidth(1f);
        dataSet.setHighLightColor(this.getResources().getColor(R.color.highlight));
    }

    public void setHighLightColor(int color) {
        this.mHighLightColor = color;
    }

    public void setXAxisTextPosition(int position) {
        mlineChartXAxis.setTextPosition(position);
    }

    public void setXAxisValueFormatter(XValueFormatter formatter) {
        mlineChartXAxis.setValueFormatter(formatter);
    }

    public void showXAxisLabels(boolean enable) {
        mlineChartXAxis.setDrawLabels(enable);
    }

    public void setYAxisOffset(float offset) {
        mlineChartAxisLeft.setXOffset(offset);
        mlineChartAxisRight.setXOffset(offset);
    }

    @Override
    public void invalidate() {
        super.invalidate();
        mLineChart.invalidate();
        mBarChart.invalidate();
    }

    public void setNoDataText(String txt) {
        mLineChart.setNoDataText(txt);
        mLineChart.invalidate();
    }

    public void setOnChartGestureListener(OnChartGestureListener l) {
        mLineChart.setOnChartGestureListener(l);
    }

    public void setYLabelColors(int... colors) {
        mlineChartAxisLeft.setTextColors(colors);
        mlineChartAxisRight.setTextColors(colors);
    }

    public void setShinePointView(ShinePointView view) {
        mLineChart.setShinePointView(view);
    }

    boolean showPoint = true;

    public void setShinePointStatus(boolean isShow) {
        this.showPoint = isShow;
        mLineChart.setShinePointStatus(showPoint);

    }

    public void setExtraTopOffset(float v) {
        mLineChart.setExtraTopOffset(v);
    }

    public void setDrawLinePathFillEnabled(boolean drawLinePathFillEnabled) {
        mDrawLinePathFillEnabled = drawLinePathFillEnabled;
    }


    public void setGridLineColor(int color) {
//        this.gridLineColor=color;
        mlineChartAxisLeft.setGridColor(color);
        mlineChartAxisRight.setGridColor(color);
        mlineChartXAxis.setGridColor(color);
        mlineChartXAxis.setAxisLineColor(color);
        mbarChartAxisLeft.setGridColor(color);
        mBarChartXAxis.setGridColor(color);
        mBarChartXAxis.setAxisLineColor(color);
    }

    public void setSpaceTopAndBottom(float spaceTopAndBottom) {
        mlineChartAxisLeft.setSpaceTop(spaceTopAndBottom);
        mlineChartAxisLeft.setSpaceBottom(spaceTopAndBottom);
        mlineChartAxisRight.setSpaceTop(spaceTopAndBottom);
        mlineChartAxisRight.setSpaceBottom(spaceTopAndBottom);
    }

    public void setXAxisLabelColor(int color) {
        if (mXLabelPosition == AJXAxis.XAXISPOSITION_MIDDLE) {
            mlineChartXAxis.setTextColor(color);
        } else if (mXLabelPosition == AJXAxis.XAXISPOSITION_BOTTOM) {
            mBarChartXAxis.setTextColor(color);
        }

    }

    public void clear() {
        if (mLineChart != null && mBarChart != null) {
            mLineChart.clear();
            mBarChart.clear();
            mLineChart.invalidate();
            mBarChart.invalidate();
        }
    }

}
